import Vue from "vue";
import Vuex from "vuex";
import api from "api/api";
Vue.use(Vuex)

//暴露出去的是Vuex.Store实例对象
export default new Vuex.Store({
    state:{
        goodsList:[],//商品信息
        ratingList:[],//评论信息
        seller:{},//商家信息
    },
    getters:{},
    mutations:{
        //获取商品信息
        goodsList(state,payload){
            state.goodsList = payload;
        },
        //获取评论信息
        ratingList(state,payload){
            state.ratingList = payload;
        },
        //获取商家信息
        sellerList(state,payload){
            state.seller = payload;
        }
    },
    actions:{
        //获取商品信息
        async getGoodsList({commit}){
            const {data} = await api.mock.goods();
            commit('goodsList',data)
            return data;
        },
        //获取评论信息
        async getRatingsList({commit}){
            const {data} = await api.mock.ratings();
            commit('ratingList',data)
            return data;
        },
        //获取商家信息
        async getSellerList({commit}){
            const {data} = await api.mock.seller();
            commit('sellerList',data)
        }
    }
})